package com.ruoyi.web.controller.base;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;

import java.util.Date;
import java.util.List;
import java.util.Arrays;

import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.system.domain.base.MesValidationrules;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.IMesValidationrulesService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 关重件验证规则Controller
 *
 * @author ruoyi
 * @date 2023-02-16
 */
@Api(tags = "关重件验证规则api")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/base/validationrules" )
public class MesValidationrulesController extends BaseController {

    private final IMesValidationrulesService iMesValidationrulesService;

    /**
     * 查询关重件验证规则列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MesValidationrules mesValidationrules)
    {
        startPage();
        LambdaQueryWrapper<MesValidationrules> lqw = new LambdaQueryWrapper<MesValidationrules>();
        if (StringUtils.isNotBlank(mesValidationrules.getCode())){
            lqw.eq(MesValidationrules::getCode ,mesValidationrules.getCode());
        }
        if (mesValidationrules.getStatus() != null){
            lqw.eq(MesValidationrules::getStatus ,mesValidationrules.getStatus());
        }
        List<MesValidationrules> list = iMesValidationrulesService.list(lqw);
        return getDataTable(list);
    }

    /**
     * 查询关重件验证规则列表所有
     */
    @ApiOperation(value = "查询关重件验证规则列表所有")
    @GetMapping("/getList")
    public List<MesValidationrules> getList(MesValidationrules mesValidationrules)
    {
        LambdaQueryWrapper<MesValidationrules> lqw = new LambdaQueryWrapper<MesValidationrules>();
        if (StringUtils.isNotBlank(mesValidationrules.getCode())){
            lqw.eq(MesValidationrules::getCode ,mesValidationrules.getCode());
        }
        if (mesValidationrules.getStatus() != null){
            lqw.eq(MesValidationrules::getStatus ,mesValidationrules.getStatus());
        }
        List<MesValidationrules> list = iMesValidationrulesService.list(lqw);
        return list;
    }

    /**
     * 导出关重件验证规则列表
     */
    @Log(title = "关重件验证规则" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(MesValidationrules mesValidationrules) {
        LambdaQueryWrapper<MesValidationrules> lqw = new LambdaQueryWrapper<MesValidationrules>(mesValidationrules);
        List<MesValidationrules> list = iMesValidationrulesService.list(lqw);
        ExcelUtil<MesValidationrules> util = new ExcelUtil<MesValidationrules>(MesValidationrules. class);
        return util.exportExcel(list, "validationrules" );
    }

    /**
     * 获取关重件验证规则详细信息
     */
    @GetMapping(value = "/{id}" )
    public AjaxResult getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iMesValidationrulesService.getById(id));
    }

    /**
     * 新增关重件验证规则
     */
    @Log(title = "关重件验证规则" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesValidationrules mesValidationrules) {
        mesValidationrules.setCreateBy(SecurityUtils.getUsername());
        mesValidationrules.setCreateTime(new Date());
        return toAjax(iMesValidationrulesService.save(mesValidationrules) ? 1 : 0);
    }

    /**
     * 修改关重件验证规则
     */
    @Log(title = "关重件验证规则" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesValidationrules mesValidationrules) {
        mesValidationrules.setUpdateBy(SecurityUtils.getUsername());
        mesValidationrules.setUpdateTime(new Date());
        return toAjax(iMesValidationrulesService.updateById(mesValidationrules) ? 1 : 0);
    }

    /**
     * 删除关重件验证规则
     */
    @Log(title = "关重件验证规则" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iMesValidationrulesService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }
}
